<?php
/* @var $this HistJurnalController */
/* @var $model HistJurnal */
/* @var $form TbActiveForm */
?>

<div class="form">

    <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'id'=>'hist-jurnal-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

    <p class="help-block">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>
	  <?php // echo $form->textFieldControlGroup($model,'jurnal_no',array('span'=>5,'maxlength'=>50,'class'=>'form-control')); ?>
	   <?php echo $form->textFieldControlGroup($model,'trx_date',array('span'=>5,'class'=>'form-control input-width-small','data-mask'=>"99-99-9999",'value'=>date('d-m-Y'))); ?>
	<table class="table table-hover table-striped table-bordered table-highlight-head" id="tbl_neraca">
	<thead>
		<th style="text-align:center">No.</th>
		<th style="text-align:center">Account Code</th>
		<th style="text-align:center">Description</th>
		<th style="text-align:center">Debet</th>
		<th style="text-align:center">Credit</th>
	</thead>
	<tbody>
		<?php for ($i=1;$i<=10;$i++){ ?>
		<tr>
			<td><?=$i?></td>
			<td>
				<?php echo $form->dropDownList($model,'mst_account_id',CHtml::listData(MstCoa::model()->findAll(' 1=1 order by code'), 'id','name'), array('empty'=>'--Pilih COA--','class'=>'form-control','name'=>'account_code[]')); ?>
			</td>
			<td>
				  <?php echo $form->textArea($model,'description',array('span'=>5,'maxlength'=>100,'class'=>'form-control','name'=>'desc[]')); ?>
			</td>
			<td>
				 <?php echo $form->textField($model,'debet',array('span'=>5,'class'=>'form-control','name'=>'debet[]','id'=>'debet_'.$i)); ?>
			</td>
			<td>
				 <?php echo $form->textField($model,'credit',array('span'=>5,'class'=>'form-control','name'=>'credit[]','id'=>'credit_'.$i)); ?>
			</td>
		</tr>
		<?php } ?>
	</tbody>
	</table>
          

          


        <div  class="form-actions">
			<div id="div_action" style="display:none;">
			<?php echo TbHtml::submitButton($model->isNewRecord ? 'SIMPAN' : 'Save',array(
				'color'=>TbHtml::BUTTON_COLOR_PRIMARY,
				'size'=>TbHtml::BUTTON_SIZE_LARGE,
			)); ?>
			</div>
			<div id="div_balance">
				<input type="button" class="btn btn-primary" value="Check Balance" id="btn_balance" />
			</div>
		</div>

    <?php $this->endWidget(); ?>

</div><!-- form -->

<script type="text/javascript">

$(document).ready(function(){
	
});

$("#btn_balance").click(function(){
	var total_debet = 0.0;
	var total_credit = 0.0;
	$('input[name="debet[]"]').each(function(i,item) {
		var item = parseFloat($(this).val());
		if (isNaN(item)) item = 0;
		total_debet += item;
	});
	
	$('input[name="credit[]"]').each(function(i,item) {
		var item = parseFloat($(this).val());
		if (isNaN(item)) item = 0;
		total_credit += item;
	});
	if(total_debet != total_credit){
		alert('Transaksi Tidak Balance, Check !!!');
	}else{
		$("#div_balance").hide();
		$("#div_action").show();
	}
});
</script>